﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using vconf_shared;

namespace vconf_server
{
    class VConfServer : MarshalByRefObject, IVConf
    {
        public VConfServer()
        {
            Console.WriteLine("VConfServer object created!");
        }

        public bool SendHeartbeat(User user)
        {
            Console.WriteLine("[DEBUG] SendHeartbeat called by: " + user.Name);
            State.UpdateHeartbeatTime(user);
            return true;
        }

        public bool Register(User user)
        {
            Console.WriteLine("[DEBUG] Register called by: " + user.Name);
            user.LastHeartbeat = DateTime.Now;
            return State.RegisterUser(user);
        }

        public bool Unregister(User user)
        {
            Console.WriteLine("[DEBUG] Unregister called by: " + user.Name);
            return State.UnregisterUser(user);
        }

        public Dictionary<String, User> GetActiveUsers(User user)
        {
            Console.WriteLine("[DEBUG] GetActiveUsers called by: " + user.Name);
            Dictionary<String, User> users = State.GetUsers();
            //users.Remove(user.Name);
            return users;
        }

        public bool AssignStreamURL(User user, string url)
        {
            Console.WriteLine("[DEBUG] AssignStreamURL called by: " + user.Name);
            return State.AssignStreamURL(user, url);
        }
    }
}
